﻿@model KRM.Core.tblOrderItem
@{
}
<link href="~/css/plugins/datepicker/datepicker.css" rel="stylesheet" />
<script src="~/hr/js/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script>
    
    $(document).ready(function () {
        $.ajax({
            url: "/orderview/LoadDayOff",
            success: function(data) {
                $('#datepicker1').datepicker({
                    startDate: "+@(ViewBag.StartDateAddDay)d",
                    endDate: "+@(ViewBag.StartDateAddDay+90)d",
                    todayHighlight: true,
                    format: 'dd/MM/yyyy hh:mm:ss',
                    daysOfWeekDisabled: [0, 6],
                    minViewMode: 0,
                    beforeShowDay: function(ev) {
                        var month = ev.getMonth() + 1 > 9 ? ev.getMonth() + 1 : '0' + (ev.getMonth() + 1);
                        var date = ev.getDate() > 9 ? ev.getDate() : '0' + (ev.getDate());
                        var strDate = month + '/' + date + '/' + ev.getFullYear();
                        if ($.inArray(strDate, data) != -1) {
                            return false;
                        }
                        return;
                    }
                }).on("changeDate", function(ev) {
                    var month = ev.date.getMonth() + 1 > 9 ? ev.date.getMonth() + 1 : '0' + (ev.date.getMonth() + 1);
                    var date = ev.date.getDate() > 9 ? ev.date.getDate() : '0' + (ev.date.getDate());
                    var strDate = month + '/' + date + '/' + ev.date.getFullYear();
                    $('#SelectedDate').val(strDate);
                    $('#lbSelectedDate').html(strDate);
                });
                $('#datepicker1 .datepicker .datepicker-days .table-condensed tbody tr td').each(function() {
                    $(this).removeClass('active');
                });
                @(Model.EstDeliveryDate>DateTime.MinValue?"SetSelectedDate()":"")
        }
        });
        
    });
    function SetSelectedDate() {
        $('#datepicker1').datepicker('update', new Date('@(Model.EstDeliveryDate.Year)','@(Model.EstDeliveryDate.Month-1)','@Model.EstDeliveryDate.Day'));
    }
</script>

<div id="divBoxedItems">
    <h4>Select delivery date boxed item</h4>
    <div class="row-fluid">
        <form id="frmSelectBoxDeliveryDate">
            <div class="span4">
            <div style="border: solid 1px gray; width: 225px;font-size: 14px;">
                <div id="datepicker1">
                </div>
                <input type="hidden"id="SelectedDate" name="SelectedDate"/>
                <b id="lbSelectedDate" style="padding-left: 10px"></b>
            </div>
            </div>
            <div class="span5"><button type="submit" class="btn btn-primary">Change date</button></div>
        </form>
    </div>
    <div class="row-fluid">
        <p style="font-weight:bold;">Current delivery date: @Model.EstDeliveryDate.ToString("MM/dd/yyyy")</p>
    </div>
</div>